package com.zjitc.service.imp;/**
 * Create by IntelliJ IDEA
 *
 * @author: MaoYongQi
 * @date-Time: 2018/4/2 11:23
 * @description:
 */

import com.zjitc.common.ServerResponse;
import com.zjitc.dao.OrderDao;
import com.zjitc.dao.ProductDao;
import com.zjitc.dao.UserDao;
import com.zjitc.model.Managecount;
import com.zjitc.service.ManageService;
import com.zjitc.utils.Conster;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * Create by IntelliJ IDEA
 *
 * @author: MaoYongQi
 * @date-Time: 2018/4/2 11:23
 * @description:
 */
@Service
public class ManageServiceImpl implements ManageService {

  @Autowired
  private UserDao udao;

  @Autowired
  private ProductDao pdao;

  @Autowired
  private OrderDao odao;

  @Override
  public ServerResponse<Managecount> statistical(HttpSession session) {
    Object user = session.getAttribute(Conster.BACKUSER);
    if (user == null) {
      return ServerResponse.createBackError("用户未登录，请登录");
    }
    try {
      int usercount = udao.findAllCount();
      int productcount = pdao.findAllCount();
      int ordercount = odao.findAllCount();
      Managecount managecount = new Managecount(usercount, productcount, ordercount);
      return ServerResponse.createSuccess(managecount);
    } catch (Exception e) {
      e.printStackTrace();
      return ServerResponse.createError("出错了");
    }
  }
}
